<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>注册</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../css/swiper.min.css" />
    <link rel="stylesheet" type="text/css" href="../css/layer.css" />
    <link rel="stylesheet" type="text/css" href="../css/mdw.css" />
    <script type="text/javascript" src="../script/api.js"></script>
    <script type="text/javascript" src="../script/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="../script/swiper.min.js"></script>
    <script type="text/javascript" src="../script/mobile.js"></script>
    <script type="text/javascript" src="../script/layer.js"></script>
    <script type="text/javascript" src="../script/mdw.js"></script>
    <script type="text/javascript" src="../script/jumpPage.js"></script>
</head>
<body>
    <header class="header loginHeader">
        <div class="backPrevPage" onclick="historyBack()"></div>
        <div class="pageTitle">绑定信息</div>

    </header>
    <section class="loginBox HTML_BOX">

    </section>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    var param;
    apiready = function(){
        $api.fixStatusBar($api.dom('header'));
        api.addEventListener({
            name: 'chooseloading'
        }, function(ret, err) {
            var data =ret.value;
            $("#gjid").val(data.id);
            $("#gjname").val(data.name);
        });
        api.addEventListener({
            name: 'reload'
        }, function(ret, err) {
           historyBack();
        });
        api.setStatusBarStyle({
            color: '#fff',//设置APP状态栏背景色
            style: 'dark'
        });
        param = api.pageParam;
        ifCnAndEn();

    };

    function loginBtn(){
        var layers = "";
        var isnull = false;
        $(".forget input").each(function(i,item){
            var val = $(item).val();
            if(val == "" && !isnull){
                switch(i){
                    case 1:
                    layers = "请输入手机号或邮箱";
                    if(cnen==2){
                        layers = 'Please enter your cell phone number or Email';
                    }
                    isnull = true;
                    break;
                    case 2:
                    layers = "请输入验证码";
                    if(cnen==2){
                        layers = 'Please enter the validation code';
                    }
                    isnull = true;
                    break;
                    case 3:
                    layers = "请输入密码";
                    if(cnen==2){
                        layers = 'Please input a password';
                    }
                    isnull = true;
                    break;
                    case 4:
                    layers = "情再次输入密码";
                    if(cnen==2){
                        layers = 'Please make sure the password is correct';
                    }
                    isnull = true;
                    break;
                }
            }
        });
        if(isnull){
            console.log(layers);
            pop.notice(layers);
            return;
        }
        if(!$(".remember").hasClass("on")){
            layers = "请同意我们的服务条款";
            if(cnen==2){
                layers = "Please agree to our terms of service.";
            }
            pop.notice(layers);
            return;
        }
        var v = regPhoneOrEmail($("#phone").val());
        if(v!=""){
            pop.notice(v);
            return;
        }
        if($("#password").val() != $("#repassword").val()){
            if(cnen==1){
                pop.notice("两次密码不一致");
            }else{
                pop.notice("Two password inconsistencies");
            }
            return;
        }
        var gj = $("#gjid").val();
        if(gj==""||gj ==null){
           if(cnen==1){
                pop.notice('请选择国家');
            }else{
                pop.notice('Please Select Country');
            }
            return;
        }
        var p ={
            country:gj,number:$("#phone").val(),
            verify:$("#yzm").val(),
            password:$("#password").val(),
            repassword:$("#repassword").val(),
            user_auth:1,
            facebook_id:param.facebook_id,
        }
        console.log(JSON.stringify(p));
        pop.loading();
        getAjax(Interface.register,p,function(res){
            pop.close();
            $api.setStorage('user',res.data);
            $api.setStorage('user_type',res.data.user_type);
            $api.setStorage('token',res.data.token);
            if($(".remember").hasClass("on")){
               $api.setStorage('loginStorage',JSON.stringify({user:$(".loginForm input").eq(0).val(),password:$(".loginForm input").eq(1).val()}));
            }else{
                 $api.setStorage('loginStorage',null);
            }
            api.sendEvent({
                name: 'reload',
                extra: {}
            });
            pop.notice('登录成功',1,function(){
                historyBack();
            })
        },function(res,err){})

    }
    function gobing(){
        openWin('login_fb','login_fb.html',param);
    }

    function hqyzmCn(){
        var html = $(".hq_yzm").html();
        var phone = $("#phone").val();
        var gj = $("#gjid").val();
        var v = regPhoneOrEmail(phone);
        if(html =="获取验证码"){
            if(v!=""){
                pop.notice(v);
                return;
            }
            var gj = $("#gjid").val();
            if(gj==""||gj ==null){
               if(cnen==1){
                    pop.notice('请选择国家');
                }else{
                    pop.notice('Please Select Country');
                }
                return;
            }
            var p ={country:gj,number:phone,type:1};
            getAjax(Interface.send_verify,p,function(res){
                pop.notice("短信验证码已发送");
                $(".hq_yzm").addClass("on");
                $(".hq_yzm").html(yzmtime + "秒后重试");
                zym = setInterval(yzmsetInterval,1000);
            })

        }
    }
    function hqyzmEn(){
        var html = $(".hq_yzm").html();
        var phone = $("#phone").val();
        var gj = $("#gjid").val();
        var v = regPhoneOrEmail(phone);
        if(html =="Send Code"){
            if(v!=""){
                pop.notice(v);
                return;
            }
            var gj = $("#gjid").val();
            if(gj==""||gj ==null){
               if(cnen==1){
                    pop.notice('请选择国家');
                }else{
                    pop.notice('Please Select Country');
                }
                return;
            }
            var p ={country:gj,number:phone,type:1};
            getAjax(Interface.send_verify,p,function(res){
                pop.notice("SMS has been sent");
                $(".hq_yzm").addClass("on");
                $(".hq_yzm").html(yzmtime + "s retry");
                zym = setInterval(yzmsetInterval,1000);
            })

        }
    }

    function chooseloading(id,name){
        alert(id+name);
    }
</script>
<script type="text/javascript">
    function ifCnAndEn(){
        var html = '';
        if(cnen==1){
            $(".pageTitle").html("绑定信息");
            html +='<div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>'+
                        '<div class="logo">'+
                            '<img src="../image/logo.png" alt="">'+
                        '</div>'+
                        '<ul class="registerForm plr">'+
                            '<li class="gj">'+
                                '<span>国家</span>'+
                                '<input id="gjname" readonly="readonly" placeholder="请选择国家"   />'+
                                '<input id="gjid" type="hidden" value=""  />'+
                                '<i></i>'+
                            '</li>'+
                            '<li class="">'+
                                '<span>账号</span>'+
                                '<input id="phone" placeholder="请输入手机号或邮箱"  />'+
                            '</li>'+
                            '<li class="hq_yzmBox">'+
                                '<span>验证码</span>'+
                                '<input id="yzm" placeholder="请输入验证码"  />'+
                                '<div onclick="hqyzmCn()" class="hq_yzm">获取验证码</div>'+
                            '</li>'+
                            '<li class="">'+
                                '<span>密码</span>'+
                                '<input id="password" type="password" placeholder="请输入密码"  />'+
                            '</li>'+
                            '<li class="">'+
                                '<span>确认密码</span>'+
                                '<input id="repassword" type="password" placeholder="情再次输入密码"  />'+
                            '</li>'+
                        '</ul>'+
                        '<div class="displayFlex plr" style="margin-top: .25rem;color:#b2b2b2;">'+
                            '<div class="remember permit"><i class="icon"></i><span>已阅读并同意软件许可</span></div>'+
                        '</div>'+
                        '<div onclick="loginBtn();" class="loginBtn f_c">绑定</div>'+
                        '<div class="f_c" style="margin-top:.3rem;font-size:.26rem;color:#999;">已有账号，<span style="color:#f41860" onclick="gobing()">点击这里前去绑定</span></div>';

        }else{
          $(".pageTitle").html("Binding information");
          html +='<div class="bg-eee" style="border-bottom:.2rem solid #EEE ; "></div>'+
                      '<div class="logo">'+
                          '<img src="../image/logo.png" alt="">'+
                      '</div>'+
                      '<ul class="registerForm plr">'+
                          '<li class="gj">'+
                              '<span>Country</span>'+
                              '<input id="gjname" readonly="readonly" placeholder="Select Country"   />'+
                              '<input id="gjid" type="hidden" value=""  />'+
                              '<i></i>'+
                          '</li>'+
                          '<li class="">'+
                              '<span>Cell Phone</span>'+
                              '<input id="phone" placeholder="Enter Cell Phone Number"  />'+
                          '</li>'+
                          '<li class="hq_yzmBox">'+
                              '<span> Security Code</span>'+
                              '<input id="yzm" placeholder="Enter Security Code"  />'+
                              '<div onclick="hqyzmEn()" class="hq_yzm">Send Code</div>'+
                          '</li>'+
                          '<li class="">'+
                              '<span>Password</span>'+
                              '<input id="password" type="password" placeholder="6-20 Digits Numbers and Letters"  />'+
                          '</li>'+
                          '<li class="">'+
                              '<span>Confirm Password</span>'+
                              '<input id="repassword" type="password" placeholder=" Enter Password Again"  />'+
                          '</li>'+
                      '</ul>'+
                      '<div class="displayFlex plr" style="margin-top: .25rem;color:#b2b2b2;">'+
                          '<div class="remember rememberEng permit"><i class="icon"></i><span>I have read and accept to the terms</span></div>'+
                      '</div>'+
                      '<div onclick="loginBtn();" class="loginBtn f_c">Bind</div>'+
                      '<div class="f_c" style="margin-top:.3rem;font-size:.26rem;color:#999;"> Have an account already? <span style="color:#f41860" onclick="gobing()">Click here to bind</span></div>';

        }
        $(".loginBox").html(html);
        $(".gj").click(function(){
            openWin('address_choose','address_choose.html');
        })

        $(".remember .icon").click(function(){
            var ison = $(".remember").hasClass("on");
            if(ison){
               $(".remember").removeClass("on");
            }else{
               $(".remember").addClass("on");
            }
        })
    }

</script>
</html>
